package Sort;

import java.util.Arrays;

/**
 * @author zhangmin
 * @create 2022-04-18 11:08
 * 希尔排序
 */
public class ShellSort<T extends Comparable<T>> extends Sort<T> {
    @Override
    public void sort(T[] nums) {
        int n=nums.length;
        int h=1;
        while (h<n/3){
            h=3*h+1;
        }
        while (h>=1){
            for (int i = h; i < n; i++) {
                for (int j = i; j >=h&&less(nums[j],nums[j-h]); j-=h) {
                    swap(nums,j,j-h);
                }
            }
            h=h/3;
        }
    }
    public static void main(String[] args) {
        Integer[] nums={3,5,6,4,1,2};
        ShellSort<Integer> shellSort=new ShellSort<Integer>();
        shellSort.sort(nums);
        System.out.println(Arrays.toString(nums));
    }
}
